service.service("requestService",['$rootScope',function($rootScope){

    var requestService={};

    /**
     * ajax请求
     * @param type
     * @param url
     * @param params
     * @param successCallback
     * @param errorCallback
     */
    requestService.ajax=function(type,url,params,successCallback,errorCallback){
        core.ui.progress.show();

        $.ajax({
            type:type,
            url:url,
            data:$.param(params,true),
            success:function(data){
                core.ui.progress.hide();

                if(objectUtil.isNull(successCallback)) {
                    return;
                }

                successCallback(data);
                $rootScope.$apply();
            },
            error:function(){
                core.ui.progress.hide();

                if(objectUtil.isNull(errorCallback)) {
                    return;
                }

                errorCallback();
                $rootScope.$apply();
            }
        });
    };

    /**
     * get请求
     * @param url
     * @param params
     * @param successCallback
     * @param errorCallback
     */
    requestService.get=function(url,params,successCallback,errorCallback){
        requestService.ajax("GET",url,params,successCallback,errorCallback);
    };

    /**
     * post请求
     * @param url
     * @param params
     * @param successCallback
     * @param errorCallback
     */
    requestService.post=function(url,params,successCallback,errorCallback){
        requestService.ajax("POST",url,params,successCallback,errorCallback);
    };

    /**
     * get api
     * @param url
     * @param params
     * @param successCallback
     * @param errorCallback
     */
    requestService.getApi=function(url,params,successCallback,errorCallback){
        requestService.get(constants.API_PATH+url,params,successCallback,errorCallback);
    };

    /**
     * post api
     * @param url
     * @param params
     * @param successCallback
     * @param errorCallback
     */
    requestService.postApi=function(url,params,successCallback,errorCallback){
        requestService.post(constants.API_PATH+url,params,successCallback,errorCallback);
    };

    return requestService;
}]);